package com.zyh.work2

object WorkerTest{
  def main(args: Array[String]): Unit = {
    val worker = new Worker("张三",26,10000.0)
    worker.address = new Address("北京市海淀区清华园1号院","100010")
    worker.work()
    worker.work(12)
    println(worker)
  }
}
case class Worker(){
  var name: String = _
  var age: Int = _
  var salary: Double = _
  var address: Address = _

  def this(name:String,age:Int,salary:Double) = {
    this
    this.name=name
    this.age=age
    this.salary=salary
  }

  def work() = println("工作")
  def work(hours:Double): Unit = println(s"工作了${hours}小时")

  override def toString: String = {
    s"name = $name,age = $age,salary = $salary,address = $address"
  }
}
case class Address(){
  var addr: String = _
  var zipCode: String = _

  def this(addr:String,zipCode:String) = {
    this
    this.addr=addr
    this.zipCode=zipCode
  }

  override def toString: String = {
    s"$addr,$zipCode"
  }
}